﻿using Framework.Common;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Framework.Math;
/**
 * Copyright 2018 北京伯睿科技有限公司.
 * All Rights Reserved.
 *  
 *
 * @TerrainsMove
 * @TerrainsMove 地形控制类
 *
 * @Author 牛瑞杰
 * @Date 2019年9月5日
 * @Version 1.0
 */
namespace BridgeShips {
    public class TerrainsMove :  MonoSingleton<TerrainsMove> {

        private Transform canMoveTerrain;
       // private Transform staticTerrain;
        private Transform bridgePoint1;
        private Transform bridgePoint2;

        private Vector3 BridgePointBottleRightResult;   //unity 场景的 右下角坐标
        private Vector3 BridgePointTopLeftResult;          //unity 场景的 左上角坐标

        private float regionEdgeLenght = 1000.0f;        // 有效区域边长500m
        private float repairLength = 262.4f;


        void Start() {
            canMoveTerrain = transform.Find( "Terrain_Move" );
            bridgePoint1 = transform.Find( "BridgePoint1" );
            bridgePoint2 = transform.Find( "BridgePoint2" );

            CaculateRectRegionPointResult();
        }

        public void InitShip()
        {

            TransferOfAxes.Instance.InitBridgePosition();
        }

        public void CaculateRectRegionPointResult()
        {

            Vector3 centerPos = (bridgePoint1.position + bridgePoint2.position) * 0.5f;
            BridgePointBottleRightResult = new Vector3(centerPos.x - regionEdgeLenght, 7.0f, centerPos.z + regionEdgeLenght);
            BridgePointTopLeftResult = new Vector3(centerPos.x + regionEdgeLenght, 7.0f, centerPos.z - regionEdgeLenght);
        }
        void Update() { }

        /// <summary>
        /// 设置两个架桥点之间的距离
        /// </summary>
        /// <param name="dis"></param>
        public void SetWidth(float dis) {
            if (dis<=60f) {
                Debug.Log( "河宽不能小于30米" );
                return;
            }
            else if (dis>=1000f) {
                Debug.Log( "河宽不能大于1000米" );
                return;
            }

            TransferOfAxes.Instance.InitBridgePosition();
            //岛屿2的坐标
            dis = TransferOfAxes.Instance.GetRiverWidth();
            canMoveTerrain.position = new Vector3(dis + repairLength, 0.0f,0.0f);
            GameEntry.Instance.VirtualRManager.Update();
        }
        public Vector3 GetBridgePointBottleRightResult() {
            return BridgePointBottleRightResult;
        }
        public Vector3 GetBridgePointTopLeftResult() {
            return BridgePointTopLeftResult;
        }

        public Transform GetBridgePoint1()
        {
            return bridgePoint1;
        }
        public Transform GetBridgePoint2()
        {
            return bridgePoint2;
        }
        public float GetRegionEdgeLenght()
        {
            return regionEdgeLenght;
        }
        
        public void SetBridgePoint2(Vector3 pos ) {
            bridgePoint2.SetPositionAndRotation( pos, Quaternion.identity );
        }

        public Transform GetWorldMatrix() {
            return bridgePoint2.transform.parent.transform;
        }

        public Transform GetBottomRightBridgeTransform()
        {
            return bridgePoint1.transform;
        }

        public Transform GetTopLeftBridgeTransform()
        {
            return bridgePoint2.transform;
        }
    }
}
